package com.aspire.nm.component.cmppserver.deliverListenerDefault;

import java.util.Hashtable;
import java.util.concurrent.LinkedBlockingQueue;


public class BlockQueues<T>{
    
    private Hashtable<String,LinkedBlockingQueue<T>> mo = new Hashtable<String,LinkedBlockingQueue<T>>();
     
    
    public T take(String key){
        if(mo.get(key) == null){
            synchronized(this){
                if(mo.get(key) == null){
                    mo.put(key, new LinkedBlockingQueue<T>());
                }
            }
        }
        try {
            return mo.get(key).take();
        } catch (InterruptedException e) {
            return null;
        }
    }
    
    public boolean put(String key,T t) {
        if(mo.get(key) == null){
            synchronized(this){
                if(mo.get(key) == null){
                    mo.put(key, new LinkedBlockingQueue<T>());
                }
            }
        }
        try {
            mo.get(key).put(t);
        } catch (InterruptedException e) {
        }
        return true;
    }
}
